package org.jeecg.glr.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.glr.entity.GlrVideo;
import org.jeecg.glr.entity.GlrVideoBd;
import org.jeecg.glr.service.IGlrVideoBdService;
import org.jeecg.glr.service.IGlrVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description: 海康摄像头人脸检测百度帐号
 * @Author: jeecg-boot
 * @Date:   2020-02-11
 * @Version: V1.0
 */
@RestController
@RequestMapping("/glr/glrVideoBd")
@Slf4j
public class GlrVideoBdController extends JeecgController<GlrVideoBd, IGlrVideoBdService> {
	@Autowired
	private IGlrVideoBdService glrVideoBdService;
	
	/**
	 * 分页列表查询
	 *
	 * @param glrVideoBd
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@GetMapping(value = "/list")
	public Result<?> queryPageList(GlrVideoBd glrVideoBd,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<GlrVideoBd> queryWrapper = QueryGenerator.initQueryWrapperCode(glrVideoBd, req.getParameterMap());
		Page<GlrVideoBd> page = new Page<GlrVideoBd>(pageNo, pageSize);
		IPage<GlrVideoBd> pageList = glrVideoBdService.page(page, queryWrapper);
		return Result.ok(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param glrVideoBd
	 * @return
	 */
	@AutoLog(value = "添加海康摄像头人脸检测百度帐号",logType= CommonConstant.LOG_TYPE_2)
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody GlrVideoBd glrVideoBd) {
		glrVideoBdService.save(glrVideoBd);
		return Result.ok("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param glrVideoBd
	 * @return
	 */
	@AutoLog(value = "修改海康摄像头人脸检测百度帐号",logType= CommonConstant.LOG_TYPE_2)
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody GlrVideoBd glrVideoBd) {
		glrVideoBdService.updateById(glrVideoBd);
		return Result.ok("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "删除海康摄像头人脸检测百度帐号",logType= CommonConstant.LOG_TYPE_2)
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		glrVideoBdService.removeById(id);
		return Result.ok("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "批量删除海康摄像头人脸检测百度帐号",logType= CommonConstant.LOG_TYPE_2)
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.glrVideoBdService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.ok("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		GlrVideoBd glrVideoBd = glrVideoBdService.getById(id);
		if(glrVideoBd==null) {
			return Result.error("未找到对应数据");
		}
		return Result.ok(glrVideoBd);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param glrVideoBd
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, GlrVideoBd glrVideoBd) {
        return super.exportXls(request, glrVideoBd, GlrVideoBd.class, "音柱管理");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, GlrVideoBd.class);
    }

}
